/***********************************************
/gen auto by zuitools
***********************************************/
#include "pointerActivity.h"

/*TAG:GlobalVariable全局变量*/
static ZKTextView* mLabel_OIL1Ptr;
static ZKTextView* mLabel_RPMPtr;
static ZKTextView* mLabel_10Ptr;
static ZKTextView* mLabel_9Ptr;
static ZKTextView* mLabel_8Ptr;
static ZKTextView* mLabel_dirtextPtr;
static ZKTextView* mLabel_6Ptr;
static ZKTextView* mLabel_DIRPtr;
static ZKPointer* mDashbroadView_1Ptr;
static ZKTextView* mLabel_OILPtr;
static ZKTextView* mLabel_5Ptr;
static ZKTextView* mLabel_TEMPPtr;
static ZKTextView* mLabel_4Ptr;
static ZKTextView* mLabel_CURMPtr;
static ZKTextView* mLabel_3Ptr;
static ZKTextView* mLabel_TotalMPtr;
static ZKTextView* mLabel_2Ptr;
static ZKWindow* mView_1Ptr;

/*register activity*/
REGISTER_ACTIVITY(pointerActivity);

typedef struct {
	int id; // 定时器ID ， 不能重复
	int time; // 定时器  时间间隔  单位 毫秒
}S_ACTIVITY_TIMEER;

#include "logic/pointerLogic.cc"

/***********/
typedef struct {
    int id;
    const char *pApp;
} SAppInfo;

/**
 *点击跳转window
 */
static SAppInfo sAppInfoTab[] = {
//  { ID_MAIN_TEXT, "TextViewActivity" },
};

/***************/
typedef bool (*ButtonCallback)(ZKButton *pButton);
/**
 * button onclick表
 */
typedef struct {
    int id;
    ButtonCallback callback;
}S_ButtonCallback;

/*TAG:ButtonCallbackTab按键映射表*/
static S_ButtonCallback sButtonCallbackTab[] = {
};
/***************/


typedef void (*SeekBarCallback)(ZKSeekBar *pSeekBar, int progress);
typedef struct {
    int id;
    SeekBarCallback callback;
}S_ZKSeekBarCallback;
/*TAG:SeekBarCallbackTab*/
static S_ZKSeekBarCallback SZKSeekBarCallbackTab[] = {
};


typedef int (*ListViewGetItemCountCallback)(const ZKListView *pListView);
typedef void (*ListViewobtainListItemDataCallback)(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index);
typedef void (*ListViewonItemClickCallback)(ZKListView *pListView, int index, int id);
typedef struct {
    int id;
    ListViewGetItemCountCallback getListItemCountCallback;
    ListViewobtainListItemDataCallback obtainListItemDataCallback;
    ListViewonItemClickCallback onItemClickCallback;
}S_ListViewFunctionsCallback;
/*TAG:ListViewFunctionsCallback*/
static S_ListViewFunctionsCallback SListViewFunctionsCallbackTab[] = {
};


typedef void (*SlideWindowItemClickCallback)(ZKSlideWindow *pSlideWindow, int index);
typedef struct {
    int id;
    SlideWindowItemClickCallback onSlideItemClickCallback;
}S_SlideWindowItemClickCallback;
/*TAG:SlideWindowFunctionsCallbackTab*/
static S_SlideWindowItemClickCallback SSlideWindowItemClickCallbackTab[] = {
};


typedef void (*EditTextInputCallback)(const std::string &text);
typedef struct {
    int id;
    EditTextInputCallback onEditTextChangedCallback;
}S_EditTextInputCallback;
/*TAG:EditTextInputCallback*/
static S_EditTextInputCallback SEditTextInputCallbackTab[] = {
};

pointerActivity::pointerActivity() {
	//todo add init code here
}

pointerActivity::~pointerActivity() {
	//todo add init file here
    // 退出应用时需要反注册
    EASYUICONTEXT->unregisterGlobalTouchListener(this);
    onUI_quit();
    unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
}

const char* pointerActivity::getAppName() const{
	return "pointer.ftu";
}

//TAG:onCreate
void pointerActivity::onCreate() {
	Activity::onCreate();
    mLabel_OIL1Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_OIL1);
    mLabel_RPMPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_RPM);
    mLabel_10Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_10);
    mLabel_9Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_9);
    mLabel_8Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_8);
    mLabel_dirtextPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_dirtext);
    mLabel_6Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_6);
    mLabel_DIRPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_DIR);
    mDashbroadView_1Ptr = (ZKPointer*)findControlByID(ID_POINTER_DashbroadView_1);
    mLabel_OILPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_OIL);
    mLabel_5Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_5);
    mLabel_TEMPPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_TEMP);
    mLabel_4Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_4);
    mLabel_CURMPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_CURM);
    mLabel_3Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_3);
    mLabel_TotalMPtr = (ZKTextView*)findControlByID(ID_POINTER_Label_TotalM);
    mLabel_2Ptr = (ZKTextView*)findControlByID(ID_POINTER_Label_2);
    mView_1Ptr = (ZKWindow*)findControlByID(ID_POINTER_View_1);
	onUI_init();
        // 注册监听全局触摸
    EASYUICONTEXT->registerGlobalTouchListener(this);
    registerProtocolDataUpdateListener(onProtocolDataUpdate); 

    rigesterActivityTimer();
}

void pointerActivity::onClick(ZKBase *pBase) {
	//TODO: add widget onClik code 
    int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
    for (int i = 0; i < buttonTablen; ++i) {
        if (sButtonCallbackTab[i].id == pBase->getID()) {
            sButtonCallbackTab[i].callback((ZKButton*)pBase);
            break;
        }
    }


    int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
    for (int i = 0; i < len; ++i) {
        if (sAppInfoTab[i].id == pBase->getID()) {
            EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
            return;
        }
    }

	Activity::onClick(pBase);
}

void pointerActivity::onResume() {
	Activity::onResume();
}

void pointerActivity::onPause() {
	Activity::onPause();
}

void pointerActivity::onIntent(const Intent *intentPtr) {
	//TODO:  
	
	Activity::onIntent(intentPtr);
}

bool pointerActivity::onTimer(int id) {
	return onUI_Timer(id);
}

void pointerActivity::onProgressChanged(ZKSeekBar *pSeekBar, int progress){

    int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
    for (int i = 0; i < seekBarTablen; ++i) {
        if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
            SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
            break;
        }
    }
}

int pointerActivity::getListItemCount(const ZKListView *pListView) const{
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
            break;
        }
    }
    return 0;
}

void pointerActivity::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
            break;
        }
    }
}

void pointerActivity::onItemClick(ZKListView *pListView, int index, int id){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
            break;
        }
    }
}

void pointerActivity::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
    int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
            SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
            break;
        }
    }
}

bool pointerActivity::onTouchEvent(const MotionEvent &ev) {
    return onpointerActivityTouchEvent(ev);
}

void pointerActivity::onTextChanged(ZKTextView *pTextView, const std::string &text) {
    int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
            SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
            break;
        }
    }
}

void pointerActivity::rigesterActivityTimer() {
    int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
    for (int i = 0; i < tablen; ++i) {
        S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
        registerTimer(temp.id, temp.time);
    }
}
